home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
1997.ZIP
/
INPFLD10.ARC
/
INPFLD.C
< prev
next >
Wrap
Text File
|
1987-08-19
|
8KB
|
181 lines
/* --------------------------------------------------------- */
/* inpfld - Get a field of characters. The last character */
/* entered is returned to caller. Legal contains all the */
/* legal characters. If legal is empty, all characters */
/* are legal. Ibuf is the string returned. Attr is the */
/* screen attributes to use for the field. x and y are */
/* the position on the display to get input. Size is the */
/* maximum size of the field. filler is the character */
/* that will fill the unused portion of the field. Option */
/* are the input options. Options are: */
/* NOOPTS = No options chosen */
/* UPCASE = Perform uppercase translation */
/* FULFIELD = Only exit if field full or Esc pressed */
/* AUTOEXIT = Exit from field if field is full. */
/* RGHTJUST = Right justify field upon exit */
/* DISPOLD = Display and use initial value of ibuf. */
/* Otherwise ibuf will be emptied before use. */
/* To use multiple options, simply OR them together. */
/* */
/* Field Editing Keys are: */
/* Left arrow, */
/* Ctl-S - Move one character left. */
/* */
/* Right arrow, */
/* Ctl-D - Move one character right. */
/* */
/* Home, */
/* Ctl-A - Move to the start of the field. */
/* */
/* End, */
/* Ctl-F - Move to the current end of the field. */
/* */
/* Del, */
/* Ctl-G - Delete the char under the cursor. */
/* */
/* BackSpace - Delete the char to the left of cursor.*/
/* */
/* Ctl-BackSpace- Delete the entire field. */
/* */
/* Ins - Toggle insert/overwrite mode. */
/* */
/* Ctl-End - Delete to the end of the line. */
/* */
/* Ctl-Left arw - Move left one word. */
/* */
/* Ctl-Right arw- Move right one word. */
/* */
/* To end field editing, use one of Enter, Esc, Tab, */
/* BackTab, Up arrow or Down arrow; or fill the field */
/* if option 5 is selected. */
/* M. Burton 20 Jul 87 Written for TurboC V1.0 */
/* Copyright (C) 1987 by Michael Burton */
/* --------------------------------------------------------- */
#include <ctype.h>
#include <inpfld.h>
int inpfld(char *legal, char *ibuf, int attr,
int y, int x, int size, char filler, int option)
{
int pcol;
int ich;
char s[81];
int insmode;
insmode = 0;
if ((option & DISPOLD) == 0) /* Clear input string if necessary */
for(pcol=0; ibuf[pcol] != 0; pcol++) ibuf[pcol] = 0;
pcol = 0;
do
{
dispfield(y,x,size,attr,pcol+1,ibuf,filler); /* display the field */
ich = readchar(); /* get next input */
if ((ich >= 32) && (ich <=126)) /* printable ASCII? */
{
if ((option & UPCASE) == UPCASE) /* Yes. Do uppercase if needed */
if (islower(ich)) ich = toupper(ich);
if ((strlen(legal) == 0) || (strchr(legal,ich) != 0))
{ /* Char in the legal string */
if (pcol < size) /* still within the field? */
{
if ((insmode != 0) && (strlen(ibuf) < size))
{
strchins(ich,ibuf,pcol); /* insert on - insert char */
pcol++;
}
else
if ((pcol < size) && (insmode == 0))
{
if (strlen(ibuf) == pcol) *(ibuf+pcol+1) = 0;
*(ibuf+pcol) = ich; /* add char to string */
pcol++;
}
}
}
}
else
switch (ich) /* char not printable ASCII - check for ctl key */
{
case IFCTLS :
case IFLARW : {
if (pcol > 0) pcol--; /* left arrow */
break;
}
case IFCTLD :
case IFRARW : {
if (pcol < strlen(ibuf)) pcol++; /* right arrow */
break;
}
case IFCTLA :
case IFHOME : {
pcol = 0; /* home */
break;
}
case IFCTLF :
case IFEND : {
pcol = strlen(ibuf); /* end */
break;
}
case IFCTLG :
case IFDEL : {
if (pcol < strlen(ibuf)) /* del */
strndel(ibuf,pcol,1);
break;
}
case IFBKSP : {
if (pcol > 0) /* backspace */
{
pcol--;
strndel(ibuf,pcol,1);
}
break;
}
case IFCTBS : { /* delete line */
strset(ibuf,0);
/* *ibuf = 0; */
pcol = 0;
break;
}
case IFINS : {
insmode = !insmode; /* insert toggle */
insmode ? setcursor(5) : setcursor(2);
break;
}
case IFCEND : { /* ctl-end */
strndel(ibuf,pcol,(strlen(ibuf)-pcol-1));
strndel(ibuf,pcol,1);
break;
}
case IFCRAR : { /* ctl-rght arrow */
pcol = findpos(ibuf,pcol,1);
break;
}
case IFCLAR : { /* ctl-left arrow */
pcol = findpos(ibuf,pcol,0);
break;
}
} /* of switch */
if (((option & FULFIELD) == FULFIELD) && (strlen(ibuf) != size) &&
(ich != IFESC)) ich = 0;
}
/* now figure out if it is time to leave */
while ((ich != IFCR) && (ich != IFESC) && (ich != IFTAB) &&
(ich != IFBTAB) && (ich != IFUARW) && (ich != IFDARW) &&
(((option & AUTOEXIT) != AUTOEXIT) || (strlen(ibuf) != size)));
pcol = strlen(ibuf);
if ((option & RGHTJUST) == RGHTJUST)
{
strconst(s,' ',size-strlen(ibuf)); /* right justify */
strcat(s,ibuf);
}
else
{
strcpy(s,ibuf);
strconst(&s[strlen(s)],' ',size - strlen(s));
}
displine(y,x,attr,s); /* display field one final time */
setcursor(2);
return(ich);
}